package com.tvsinfo.jdk.demo.case7_parallel;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class Parallel3_method {
    public static void main(String[] args) {

        System.out.println("--------------------------");
        Parallel3_method parallel2_split=new Parallel3_method();
        for (int i = 0; i < 10; i++) {
            parallel2_split.test2();
            parallel2_split.test();
            System.out.println("--------------------------");
        }
    }
    void test() {
        List<Parallel1_Stream.ParallelCase> numbers = new LinkedList<>();
        Random random = new Random();
        for (int i = 0; i < 1000000; i++) {
            numbers.add(new Parallel1_Stream.ParallelCase(Integer.valueOf(random.nextInt(100000))));
        }
        Long startTimes = System.currentTimeMillis();
        List<Integer> collect = numbers.stream().parallel().map(Parallel1_Stream.ParallelCase::getDoCondition).limit(100).collect(Collectors.toList());
        Long endTimes = System.currentTimeMillis();
        System.out.println("parallel-> startTime：" + startTimes + " end:" + endTimes + " 总耗时：" + (endTimes - startTimes) + "ms  value:" );

    }
    void test2() {
        List<Parallel1_Stream.ParallelCase> numbers3333 = new LinkedList<>();
        Random random = new Random();
        for (int i = 0; i < 1000000; i++) {
            numbers3333.add(new Parallel1_Stream.ParallelCase(Integer.valueOf(random.nextInt(100000))));
        }
        Long startTimes = System.currentTimeMillis();
        List<Integer> collect = numbers3333.stream().map(Parallel1_Stream.ParallelCase::getDoCondition).limit(100).collect(Collectors.toList());
        Long endTimes = System.currentTimeMillis();
        System.out.println("stream-> startTime：" + startTimes + " end:" + endTimes + " 总耗时：" + (endTimes - startTimes) + "ms  value:" );
    }

}
